//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Workflow
//  File name:	Workflow.cs
//  Developer:	Solomatov Igor
//  Created:	16.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Collections.Specialized;
using Smart.Common;

namespace Smart.Workflow
{
	public static class Workflow
	{
		// Resource file name Key
		public static string ResourceKey = "Smart.Workflow";

		public static uint GetLang()
		{
			var web = SPH.GetWeb();

			return web != null ? web.Language : 1049;
		}

		public static SyncDictionary<string, string> LsD;

		public static string GetLocalizedString(string key)
		{
			if (string.IsNullOrEmpty(key))
				return key;

			var lang = GetLang();

			if (LsD == null)
				LsD = new SyncDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

			var res = LsD[key + ":" + lang];

			if (res != null)
				return res;

			res = Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString("$Resources:" + ResourceKey + "," + key + ";", ResourceKey, lang);

			if (res != null)
			{
				if (res.StartsWith("$Resources", StringComparison.OrdinalIgnoreCase))
				{
					H.LT("Resource not found: {0}", key);
				}

				LsD[key + ":" + lang] = res;
			}

			return res;
		}

		public static string Localized(this string key)
		{
			return GetLocalizedString(key);
		}

		public static bool IsLocalized(this string key)
		{
			return key != null && key.StartsWith("$Resources", StringComparison.OrdinalIgnoreCase);
		}
	}
}